package cn.infomany.controller;
import cn.infomany.common.domain.PageParamDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author zjb
 * @since 2020-06-08
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/tbUser")
public class TbUserController {

    @Autowired
    private ITbUserService tbUserService;

    /**
     * 分页列表查询
     *
     * @param tbUserPageListDTO
     * @param pageParamDto
     * @return
     */
    @GetMapping(value = "/list")
    public Result queryPageList(@Valid @RequestBody PageListTbUserDTO pageListTbUserDTO,
    							@Valid @RequestBody PageParamDTO pageParamDto) {
    	return tbUserService.pageTbUser(pageListTbUserDTO, pageParamDto);
    }

    /**
     * 添加
     *
     * @param tbUser
     * @return
     */
    @PostMapping
    public Result add(@Valid @RequestBody AddTbUserDTO addTbUserDTO) {
    	return tbUserService.saveTbUser(addTbUserDTO);
    }
    
    /**
     * 编辑
     *
     * @param tbUser
     * @return
     */
    @PutMapping
    public Result edit(@Valid @RequestBody EditTbUserDTO editTbUserDTO) {
    	tbUserService.updateTbUser(editTbUserDTO);
    	return Result.success();
    }
    
    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping
    public Result delete(@NotNull(message = "id不能为空") @RequestParam String id) {
    	tbUserService.removeTbUserById(id);
    	return Result.success();
    }
    
    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteBatch")
    public Result deleteBatch(@NotNull(message = "ids不能为空")
                              @Size(min = 1,message = "删除数量不能小于1")
                              @RequestParam String[] ids) {
    	this.tbUserService.removeTbUserByIds(ids);
    	return Result.success();
    }
    
    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping
    public Result queryById(@NotNull(message = "id不能为空") @RequestParam String id) {
    	return tbUserService.findTbUserById(id);
    }

}
